﻿using System;

using Game.Common;

namespace Game.Actions
{
    public class ActionEventArgs : EventArgs 
    {
        readonly GameAction _GameAction;
        
        public ActionEventArgs(GameAction action)
        {
            _GameAction = action;
        }
        
        public GameAction GameAction
        {
            get { return _GameAction; }
        }
    }
    
    /// <summary>
    /// A GameAction is an modification of something on a map.
    /// </summary>
    public class GameAction
    {
        public event EventHandler<ActionEventArgs> Executed;
        
        public virtual bool CanExecute()
        {
            return true;
        }

        protected virtual ActionResult Execute(GameTurn turn,
                                               Context context )
        {
            context.ActionExecutor.Done(turn, true);
            return null;
        }
        
        protected internal ActionResult DoExecute(GameTurn turn,
                                                  Context context )
        {
            ActionResult result = Execute(turn, context);
            
            if (Executed != null)
            {
                Executed(this, new ActionEventArgs(this));
            }
            
            return result;
        }
        
    }
}
